package abstractdemo;

public class Triangle extends Shape {

    int a, b, c;

    Triangle(int a, int b, int c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    //判断是否构成三角形
    public boolean isTrigle() {
        if (a + b <= c || a + c <= b || b + c <= a) {
            System.out.println("不构成三角形");
            return false;
        }
        return true;
    }

    //方法重写
    @Override
    public double getArea() {
        if (this.isTrigle()) {
            double p = (a + b + c) / 2.0;
            return Math.sqrt(p * (p - a) * (p - b) * (p - c));//海伦公式计算三角形面积
        } else {
            return -1;
        }
    }

    //方法重写
    @Override
    public double getCircle() {
        if (this.isTrigle()) {
            return a + b + c;
        } else {
            return -1;
        }
    }
}
